package com.lmx.persistence.service;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.lmx.common.context.ActionContextHolder;
import com.lmx.repoDomain.tmodel.EmployeeAchievementsType;
import com.lmx.repoDomain.tmodel.EmployeeAchievementsTypeItem;

/**
 * 绩效类型 service
 *
 * @author ytche
 * @date 2017年7月20日
 *
 */
@Service
@Scope("prototype")
public class EmployeeAchievementsTypeService<T> {
	
	@PersistenceContext
	private EntityManager em;
	
	/**
	 * 获取checkLevelRelations
	 */
	public int checkLevelRelations(EmployeeAchievementsType type) {
		int flag = 0;
		Long id = type.getId();
		List projectList = new ArrayList<>();
		projectList = this.em
				.createQuery(
						"select c from EmployeeAchievementsTypeItem c where c.delStatus != ?1 and c.tenant.id=?2 and c.achievementsType.id=?3 ")
				.setParameter(1, (short) 1)
				.setParameter(2, ActionContextHolder.getContext().getTenantId())
				.setParameter(3, id).getResultList();

		flag += projectList.size();
		return flag;
	}
	
	/**
	 * 获取checkItemRelations
	 */
	public int checkItemRelations(EmployeeAchievementsTypeItem item) {
		int flag = 0;
		Long id = item.getId();

		List scopeList = new ArrayList<>();
		scopeList = this.em
				.createQuery(
						"select c from EmployeeProformance c where c.delStatus != ?1 and c.tenant.id=?2 and c.achievementsTypeItem.id=?3 ")
				.setParameter(1, (short) 1)
				.setParameter(2, ActionContextHolder.getContext().getTenantId())
				.setParameter(3, id).getResultList();

		flag += scopeList.size();
		return flag;
	}
	
}
